<template>
  <Form ref="form" :model="form" :rules="rule" :label-width="100">
    <FormItem label="名称" prop="title">
      <Input v-model="form.title" placeholder=""></Input>
    </FormItem>
    <FormItem label="用户姓名" prop="realName">
      <Input v-model="form.realName" placeholder=""></Input>
    </FormItem>
    <FormItem label="用户手机号" prop="mobilePhone">
      <Input v-model="form.mobilePhone" placeholder=""></Input>
    </FormItem>
    <FormItem label="用户身份证号" prop="idCard">
      <Input v-model="form.idCard" placeholder=""></Input>
    </FormItem>
    <FormItem label="状态" prop="status">
      <Select v-model="form.status">
          <Option :value="10">初建</Option>
          <Option :value="15">已过期</Option>
          <Option :value="20">已核销</Option>
          <Option :value="25">已废弃</Option>
      </Select>
    </FormItem>
  </Form>
  </template>
<script>
import { save, update, get } from '@/api/wos/wos.ticket.service.js'

export default {
  props: {
    isEdit: {
      type: Boolean,
      default: false
    },
    params: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      form: {
        id: 0,
        title: '',
        realName: '',
        mobilePhone: '',
        idCard: '',
        status: 10
      },
      rule: {
        title: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        realName: [
          { required: true, message: '用户姓名不能为空', trigger: 'blur' }
        ],
        mobilePhone: [
          { required: true, message: '用户手机号不能为空', trigger: 'blur' }
        ],
        idCard: [
          { required: true, message: '用户身份证号不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  mounted () {
    if (this.isEdit) {
      get({
        id: this.params.id
      }).then(res => {
        this.form = this.$util.copy(res.data, this.form)
      })
    }
  },
  methods: {
    submit () {
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            if (this.isEdit) {
              update(this.form).then(res => {
                resolve(res)
              }).catch(e => {
                reject(e)
              })
            } else {
              delete this.form.id
              save(this.form).then(res => {
                resolve(res)
              }).catch(e => {
                reject(e)
              })
            }
          } else {
            reject(new Error('error'))
          }
        })
      })
    }
  }
}
</script>
